package com.rao.gmall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rao.gmall.common.result.Result;
import com.rao.gmall.model.list.Goods;
import com.rao.gmall.model.product.SkuInfo;
import com.rao.gmall.product.service.SkuInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author nzmxfan
 * @create 2021-08-06-0:22
 */
@RestController
@RequestMapping("/admin/product")
public class SkuInfoController {



    @Resource
    SkuInfoService skuInfoService;

    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        skuInfoService.saveSkuInfo(skuInfo);
        return Result.ok();
    }

    @GetMapping("/list/{page}/{limit}")
    public Result<Page<SkuInfo>> list(@PathVariable("page") Long page,
                       @PathVariable("limit") Long limit){
        Page<SkuInfo> skuInfoPage = new Page<>(page, limit);

        Page<SkuInfo> list = skuInfoService.page(skuInfoPage);
        return Result.ok(list);
    }

    @GetMapping("/onSale/{skuId}")
    public Result onSale(@PathVariable("skuId") Long skuId){

        skuInfoService.onSale(skuId);

        return Result.ok();
    }

    /**
     * es 中下架商品
     * @param skuId
     * @return
     */
    @GetMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable("skuId") Long skuId){
        skuInfoService.cancelSale(skuId);
        return  Result.ok();
    }
}
